class Validate {
    // 校验手机号
    async undefinedCheck(val, par) {
        if (val === undefined) {
            throw { msg: `${par}字段不能为空,必填`, code: 400, validata: null };
        }
    }

    // 空值和字符串校验
    async nullCheck(val, tips, par) {
        await this.undefinedCheck(val, par);
        if (val.trim() === "") {
            throw { msg: tips, code: 422, validata: null };
        }
        if (typeof val !== 'string') {
            throw { msg: `${par}字段必须是字符串类型`, code: 400, validata: null };
        }
    }

    // 数组校验
    async arrayCheck(val, tips, par) {
        await this.undefinedCheck(val, par);
        if (!Array.isArray(val)) {
            throw { msg: `${par}字段必须是数组类型`, code: 400, validata: null };
        }
        if (val.length <= 0) {
            throw { msg: tips, code: 422, validata: null };
        }
    }
}
module.exports = new Validate();